#ifndef VObjectText_First
#define VObjectText_First
#ifdef __GNUG__
#pragma interface
#endif

#include "StyledText.h"

class MarkList;
class TextView;

extern const cMarkChar; // character to mark a VisualMark

//------ VObjectText -----------------------------------------------------------

class VObjectText: public StyledText {
	MarkList *visualMarks;
	TextView *tv;

	void Init();
protected:
	void ReplaceRange(int from, int to, Text *src, int sfrom, int sto);
public:
	MetaDef(VObjectText);

	VObjectText();
	VObjectText(int cap, Font *f= gSysFont, TxtParaAlign= eTxtParaLeft);
	VObjectText(byte *buf, int l= -1, Font *f= gSysFont, TxtParaAlign= eTxtParaLeft);
	~VObjectText();
	void InitNew();

	//---- editing
	void SetCharStyle(TxtCharProp m, int f, int t, const CharStyleSpec &st);
	void ReplaceCharStyles(RunArray *styles, int from, int to);

	//---- VObject embedding
	VisualMark *GetVisualMarkAt(int at);
	byte GetMarkChar();
	void PasteVisualMark(VisualMark *vmp, int from, int to);
	void PasteVObject(VObject *vop, int from, int to);
	VObject *VObjectAt(int charNo);
	MarkList *GetVisualMarks();
	int FindPositionOfVObject(VObject*);   // -1 VObject not found
	TextView *GetTextView();
	void SetView(TextView*);

	bool IsMarkChar(int charNo);
	bool IsVisualMark(int charNo);

	void VObjectChangedSize(VObject*);
	Iterator *VisualMarksIterator();
	int VisualMarksCount();

	//---- activation/passivation
	OStream &PrintOn(OStream&);
	IStream &ReadFrom(IStream&);
	IStream &ReadFromAsPureText(IStream &s, long sizeHint);

	void CollectParts(Collection *c);
	void ClassInvariant();
};

inline bool VObjectText::IsMarkChar(int charNo)
	{ return (*this)[charNo] == cMarkChar; }

inline bool VObjectText::IsVisualMark(int charNo)
	{ return (IsMarkChar(charNo) && GetVisualMarkAt(charNo)); }

#endif
